﻿Imports System.Data.OleDb
Public Class Dabke_Search
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SqlDataSource1.SelectCommand = "SELECT [ID], [Dabka_Name], [Dabka_Picture], [Dabka_Country], [Added time], [Added by], [Dabka_Ryhthm] " & _
                                   "FROM [Dabka] WHERE " & _
                                   " ( [Dabka_Country] like ""%" & Request.QueryString("S") & "%"" ) OR " & _
                                   " ( [Dabka_Ryhthm] like ""%" & Request.QueryString("S") & "%"" ) OR " & _
                                   " ( [Dabka_Name] like ""%" & Request.QueryString("S") & "%"" ) OR " & _
                                   " ( [Added by] like ""%" & Request.QueryString("S") & "%"" )  "

        GridView1.DataBind()

        Dim searchby As String

        If User.Identity.Name <> "" Then
            searchby = User.Identity.Name
        Else
            searchby = "Anonymouse"
        End If


        Dim sql As String = "INSERT INTO SearchPhrases (S_Phrase, UserName) VALUES (@f1,@f2)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)

        cmd.Parameters.AddWithValue("@f1", Request.QueryString("S"))
        cmd.Parameters.AddWithValue("@f2", searchby)

        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
    End Sub

    Protected Sub Btn_Search_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Btn_Search.Click
        Response.Redirect("~/Dabke_Search.aspx?S=" & TB_Search.Text)
    End Sub
End Class